/**
 * Anderground project - Subway maps processor application.
 * Copyright (C) 2008-2009 Eldar Abusalimov, Ilya Shurigyn
 * 
 * This file is part of Anderground.
 * 
 * Anderground is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * Anderground is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Anderground.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.anderground.core.util;

import java.io.Serializable;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
public class Point implements Serializable {

	private static final long serialVersionUID = -3469411162713446750L;

	private int x, y;

	transient private String string;

	/**
	 * creates (0,0) Point
	 */
	public Point() {
		this.x = 0;
		this.y = 0;
	}

	/**
	 * creates a Point with specified x and y
	 * 
	 * @param x
	 * @param y
	 */
	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}

	/**
	 * creates a new Point from existing one
	 * 
	 * @param another
	 */
	public Point(Point another) {
		this.x = another.x;
		this.y = another.y;
	}

	/**
	 * @return the x
	 */
	public int getX() {
		return x;
	}

	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}

	public String toString() {
		if (string == null) {
			string = new StringBuilder().append('(').append(x).append(';')
					.append(y).append(')').toString();
		}
		return string;
	}

	@Override
	public int hashCode() {
		return toString().hashCode();
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof Point) {
			Point other = (Point) o;
			return (this.x == other.x && this.y == other.y);
		} else {
			return false;
		}
	}

}
